<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <title>制造物联中间件系统</title>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/css/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/css/xadmin.css">
    <script src="${pageContext.request.contextPath}/resources/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/resources/js/xadmin.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/resources/myjs/system/system.js"></script>
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">系统管理</a>
            <a href="">资源管理</a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5">

                        <div class="layui-inline layui-show-xs-block">
                            <select name="type" lay-verify="required">
                                <option value="res_group_type">资源组</option>
                                <option value="res_name">资源名称</option>
                                <option value="res_link">资源连接</option>
                            </select>
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="searchText" placeholder="请输入查询内容" autocomplete="off"
                                   class="layui-input">
                        </div>

                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn" lay-submit="" lay-filter="sreach"><i
                                    class="layui-icon">&#xe615;</i>
                            </button>
                        </div>
                    </form>
                </div>
                <div class="layui-card-header">
                    <button class="layui-btn layui-btn-danger" id="delAll"><i class="layui-icon"></i>批量删除
                    </button>
                    <button class="layui-btn"
                            onclick="xadmin.open('添加','${pageContext.request.contextPath}/system/res-add',800,600)">
                        <i
                                class="layui-icon"></i>添加
                    </button>
                </div>
                <div class="layui-card-body layui-table-body layui-table-main">
                    <table class="layui-table layui-form" lay-data="{id:'test'}" id="test" lay-filter="test"></table>
                </div>

            </div>
        </div>
    </div>
</div>
</body>
<%--###################################模板开始###################################--%>
<script type="text/html" id="operate">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<%--资源组--%>
<script type="text/html" id="resGroup">
    {{d.sysResGroup.resGroupType}}
</script>
<%--###################################模板结束###################################--%>
<script>
    layui.use(['laydate', 'form', 'table', 'jquery'], function () {
        var laydate = layui.laydate;
        var form = layui.form;
        var table = layui.table;
        var $ = layui.jquery;

        //实时监听input输入框,更新table
        $("input[name=searchText]").on("input", function () {
            //  具体代码
            let data = $("input[name=searchText]").val();
            if (data == '') {
                loadTable('${pageContext.request.contextPath}/system/res/list')
            }
        });

        //加载页面数据
        loadTable('${pageContext.request.contextPath}/system/res/list')

        //查询监听
        form.on('submit(sreach)',
            function (data) {
                loadTable('${pageContext.request.contextPath}/system/res/search?type=' + data.field.type + '&searchText=' + data.field.searchText)
                return false;
            });
        // 监听全选
        form.on('checkbox(checkall)', function (data) {
            if (data.elem.checked) {
                $('tbody input').prop('checked', true);
            } else {
                $('tbody input').prop('checked', false);
            }
            form.render('checkbox');
        });


        //批量删除
        table.on('checkbox(test)', function (obj) {
            var checkStatus = table.checkStatus('test');
        })
        $("#delAll").on("click", function () {
            let ids = []
            let list = table.checkStatus('test').data;
            for (let i = 0; i < list.length; i++) {
                ids.push(list[i].id)
            }
            let res = ids.join(",")
            del(res, "${pageContext.request.contextPath}/system/res/del")
        })

        //监听行工具事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    del(obj.data.id, "${pageContext.request.contextPath}/system/res/del")
                });
            } else if (obj.event === 'edit') {
                xadmin.open('编辑用户', '${pageContext.request.contextPath}/system/res-edit?id=' + obj.data.id, 800, 600)
            }
        });

        function loadTable(url) {
            table.render({
                elem: '#test'
                , url: url //数据接口
                // 对我们请求过来的数据进行一次预处理
                , parseData(res) {
                    if (res.success) {
                        return {
                            "code": 0, //解析接口状态, 等于0代表成功
                            "msg": res.msg, //解析提示文本
                            "count": res.data.total, //解析数据长度
                            "data": res.data.list//解析数据列表
                        }
                    } else {
                        layer.msg(res.msg);
                        return {
                            "code": res.code, //解析接口状态, 等于0代表成功
                            "msg": res.msg, //解析提示文本
                            "count": res.data.total, //解析数据长度
                            "data": res.data.list//解析数据列表
                        }
                    }
                },
                request: {
                    //页码的参数名称，默认：page，指定了页码的key
                    pageName: 'pageNum',
                    // 指定了每页容量的key
                    limitName: 'pageSize' //每页数据量的参数名，默认：limit
                },
                page: true, //开启分页
                cols: [
                    [ //表头
                        {type: 'checkbox'},
                        {field: 'resName', title: '资源名称'},
                        {field: 'resLink', title: '资源连接'},
                        {field: 'resType', title: '资源类型'},
                        {title: '资源组', templet: '#resGroup'},
                        {title: '操作', toolbar: '#operate'}
                    ]
                ]
            });
        }

    });


</script>
</html>
